package work.mediway.web;

import com.mediway.hos.base.config.BeanScanConfiguration;
import com.mediway.hos.security.config.SecurityConfig;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.context.request.RequestContextListener;

import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@EnableSwagger2WebMvc
@ComponentScan(
        basePackages = {
//                "com.xxl",
                "work.mediway",
                "com.mediway.hos"
        },
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
                value = {
                        SecurityConfig.class,
//                        XxlWebMvcConfig.class,
//                        IndexController.class
                }),
                @ComponentScan.Filter(
                        type = FilterType.CUSTOM,
                        classes = {
                                AutoConfigurationExcludeFilter.class
                        })
        })
@MapperScan({
        "com.mediway.**.mapper",
//        "com.xxl.**.dao",
        "com.mediway.**.dao",
        "work.mediway.**.mapper.**"
})
@SpringBootApplication(exclude = {
        BeanScanConfiguration.class
})
@EnableAsync
public class WebApplication extends SpringBootServletInitializer implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebApplication.class);
    }

    @Override
    public void run(String... args) throws Exception {

    }

    @Bean
    public RequestContextListener requestContextListener(){
        return new RequestContextListener();
    }

}